{% extends 'layout/basic.html' %}
{% load static %}
{% block title %} 用户登陆{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
    <style>
        .err-msg {
            color: red;
            position: absolute;
        }

        .form-error {
            color: red;
            position: absolute;

        }
    </style>
{% endblock %}


{% block content %}
    <div class="account">
        <div class="title">用户登陆</div>
        <form method="post" novalidate id="form-login">
            {% csrf_token %}
            {% for field in form %}
                {% if field.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <div class="clearfix">
                            <div class="col-xs-7" style="padding-left: 0">{{ field }} <span class="err-msg"></span>
                                <span class="form-error">{{ field.errors.0 }}</span>
                            </div>
                            <div class="col-xs-5" style="padding-right: 0">
                                <img src="{% url 'image_code' %}" alt="" id="image-code">
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }} <span class="form-error">{{ field.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}
            {#  通过ajax 请求发送 #}
            <div class="pull-right"><a href="{% url 'login_sms' %}">短信验证登录?</a></div>
            <button type="submit" class="btn btn-primary" id="btnLogin">登录</button>
        </form>
    </div>
{% endblock %}

{% block js %}
    <script>
        // 实现点击图片验证码 更换图片
        $('#image-code').click(function () {
            let odlSrc= $(this).attr('src')
            $(this).attr('src',odlSrc+'?')
        })
    </script>
{% endblock %}